package com.shuiyun.jdbc.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author shuiyun
 * @program jdbcdemo
 * @description 用户接口
 * @create 2021-08-11 16:31
 **/
@Mapper
@Component
public interface UserDao {

    /**
     * 保存用户信息
     * @param userId 用户ID
     * @param fullName 用户名称
     * @author shuiyun
     * @date 2021-08-11 16:36
     * @return 是否插入成功
     */
    @Insert("insert into t_user(id, full_name) value(#{userId},#{fullName})")
    int insertUser(@Param("userId")Long userId,@Param("fullName")String fullName);


    /**
     * 根据id列表查询多个用户
     * @param userIds 用户id列表
     * @return 用户信息
     */
    @Select({"<script>",
            " select",
            " * ",
            " from t_user t ",
            " where t.id in",
            "<foreach collection='userIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<Map<String, Object>> selectUserByIds(@Param("userIds") List<Long> userIds);

    /**
     * 根据id列表查询多个用户
     * @param userIds 用户id列表
     * @return 用户信息 - 类型转移
     */
    @Select({"<script>",
            " select",
            " t.user_id,t.full_name,b.value ",
            " from t_user t ,t_dict b",
            " where t.user_type = b.code and t.user_id in",
            "<foreach collection='userIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<Map<String, Object>> selectUserInfoByIds(@Param("userIds") List<Long> userIds);
}
